/**
 * Created by MetaLab_Gu on 2016/4/13.
 */
angular.module('metalabPartnerApp').directive('metaCollapse', ['$timeout', function ($timeout) {
    return {
        restrict: 'E',
        templateUrl: 'views/common/metaCollapse.html',
        transclude: true,
        scope: {
            closeCallback: "&",
            timing: "="
        },
        link: function (scope, elem, attrs) {
            scope.off = true;//开关标志
            scope.timing = scope.timing ? scope.timing : '.4';

            var element = angular.element(elem)[0];
            element.getElementsByClassName('meta-collapse-inner')[0].style.transition = scope.timing ? 'height ' + scope.timing + 's ease-out' : '';
            //element.parentNode.style.minHeight=window.getComputedStyle(element.parentNode.getElementsByClassName('meta-collapse-inverse')[0],null).height;
            /**
             * @function 关闭事件
             */
            scope.switch = function () {
                scope.off = !scope.off;
                if (!scope.off) {
                    scope.closed = false;
                }
                $timeout(function () {
                    if (scope.off) {
                        scope.closed = true;
                        scope.closeCallback();
                    }
                }, parseFloat(scope.timing) * 1000);
            }

            $timeout(function () {
                scope.switch();
            }, 2000);
        }
    };
}]);
